package com.visikard.item;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class GeoSearchItem {
	String id;
	String des;
	String ref;
	String location;
	
	public GeoSearchItem(){}
	
	public GeoSearchItem(JSONObject obj){
		id = obj.optString("id");
		des = obj.optString("description");	
		ref = obj.optString("reference");
		
		location = des;
		try {
			String t3="", t2="";
			JSONArray terms = obj.getJSONArray("terms");
			int len = terms.length();
			
			if(len>=2){
				if(len>=3)
					t3 = terms.getJSONObject(len-3).getString("value");
				t2 = terms.getJSONObject(len-2).getString("value");
				location = t3 + (t3.length()>0?", ":"") + t2;
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	public String toString(){
		//return des;
		return location;
	}
}
